﻿<UserControl xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"  x:Class="VXCompany.SilverlightLogging.WP7.MVVM.Views.LogStatusControl"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	xmlns:vm="clr-namespace:VXCompany.SilverlightLogging.MVVM.ViewModels"		 
	mc:Ignorable="d"
	FontFamily="{StaticResource PhoneFontFamilyNormal}"
	FontSize="{StaticResource PhoneFontSizeNormal}"
	Foreground="{StaticResource PhoneForegroundBrush}"
	d:DesignWidth="480" d:DesignHeight="768">
	<UserControl.Resources>
		<DataTemplate x:Key="ExceptionMessageTemplate">
			<Border BorderBrush="Blue" BorderThickness="4" CornerRadius="5" MinWidth="245">
				<StackPanel>
					<TextBlock Text="ExceptionMessageID" FontWeight="Bold"/>
					<TextBlock Text="{Binding ExceptionMessageID}" TextWrapping="Wrap" />

					<TextBlock Text="DateTime" FontWeight="Bold"/>
					<TextBlock Text="{Binding DateTime}" TextWrapping="Wrap" />

					<TextBlock Text="ClientAddress" FontWeight="Bold"/>
					<TextBlock Text="{Binding ClientAddress}" TextWrapping="Wrap" />

					<TextBlock Text="ClientApplication" FontWeight="Bold"/>
					<TextBlock Text="{Binding ClientApplication}" TextWrapping="Wrap"/>

					<TextBlock Text="Level" FontWeight="Bold"/>
					<TextBlock Text="{Binding Level}" TextWrapping="Wrap" />

					<TextBlock Text="Message" FontWeight="Bold"/>
					<TextBlock Text="{Binding Message}" TextWrapping="Wrap"/>

					<TextBlock Text="UserID" FontWeight="Bold"/>
					<TextBlock Text="{Binding UserID}" TextWrapping="Wrap"/>
				</StackPanel>
			</Border>
		</DataTemplate>

		<DataTemplate x:Key="SyncBehaviorTemplate" >
			<Border BorderBrush="Blue" BorderThickness="4" CornerRadius="5" MinWidth="245">
				<StackPanel Orientation="Vertical">
					<StackPanel Orientation="Horizontal">
						<StackPanel Margin="5">
							<TextBlock Text="Name" FontWeight="Bold"/>
							<TextBlock TextWrapping="Wrap" Text="{Binding Name}" />
						</StackPanel>
						<StackPanel Margin="5">
							<TextBlock Text="IsSynchronizing" FontWeight="Bold"/>
							<TextBlock Text="{Binding IsSynchronizing, Mode=OneWay}" />
						</StackPanel>
					</StackPanel>
					<StackPanel Orientation="Horizontal">
						<StackPanel Margin="5">
							<TextBlock Text="State" FontWeight="Bold"/>
							<TextBlock Text="{Binding State}"/>
						</StackPanel>

						<StackPanel Margin="5">
							<TextBlock Text="LastKnownSyncResult" FontWeight="Bold"/>
							<TextBlock Text="{Binding LastKnownSyncResult, Mode=OneWay}" />
						</StackPanel>
					</StackPanel>
				</StackPanel>
			</Border>
		</DataTemplate>

	</UserControl.Resources>

	<UserControl.DataContext>
		<vm:LogStatusControlViewModel />
	</UserControl.DataContext>

	<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
		<controls:Panorama HorizontalAlignment="Stretch" Height="auto" VerticalAlignment="Stretch" Width="auto" Margin="5">
			<controls:PanoramaItem Header="Settings" >

				<StackPanel Orientation="Horizontal">

					<StackPanel Orientation="Vertical" Margin="5">

						<TextBlock Text="App name" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.ApplicationName, Mode=OneWay}" />

						<TextBlock Text="ClientAddress" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.ClientAddress, Mode=OneWay}" TextWrapping="Wrap" />

						<TextBlock Text="IsUserAuthenticated" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.IsUserAuthenticated, Mode=OneWay}" />

						<TextBlock Text="MinLogLevel" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.MinLogLevel, Mode=OneWay}"  />
					</StackPanel>

					<StackPanel Orientation="Vertical" Margin="5">

						<TextBlock Text="MinSyncLevel" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.MinSyncLevel, Mode=OneWay}" />

						<TextBlock Text="SyncBehaviorFlags" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.SyncBehaviorFlags, Mode=OneWay}" TextWrapping="Wrap" />

						<TextBlock Text="SyncWhenStorageUnavailable" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.SyncWhenStorageUnavailable, Mode=OneWay}" />

						<TextBlock Text="UserID" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingConfiguration.UserID, Mode=OneWay}" TextWrapping="Wrap" />

					</StackPanel>

				</StackPanel>
			</controls:PanoramaItem>

			<controls:PanoramaItem Header="Service">
				<ScrollViewer>
					<StackPanel>

						<TextBlock Text="IsStorageAvailable" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.Store.IsStorageAvailable, Mode=OneWay}" />

						<TextBlock Text="IsServiceAvailable" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.IsServiceAvailable, Mode=OneWay}" />

						<TextBlock Text="IsSynchronizing" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.IsSynchronizing, Mode=OneWay}" />

						<TextBlock Text="AbsoluteUri" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingServiceClient.Endpoint.Address.Uri.AbsoluteUri, Mode=OneWay}" TextWrapping="Wrap" />

						<TextBlock Text="Port" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingServiceClient.Endpoint.Address.Uri.Port, Mode=OneWay}" />

						<TextBlock Text="State" FontWeight="Bold"/>
						<TextBlock Text="{Binding ExceptionPolicy.LoggingServiceClient.State, Mode=OneWay}" />

						<TextBlock Text="SyncBehaviors" FontWeight="Bold"/>
						<ListBox ItemTemplate="{StaticResource SyncBehaviorTemplate}" ItemsSource="{Binding ExceptionPolicy.RunningSyncBehaviors, Mode=OneWay}" IsHitTestVisible="False" />

					</StackPanel>
				</ScrollViewer>
			</controls:PanoramaItem>

			<controls:PanoramaItem Header="Stored Errors">
				<ScrollViewer>
					<StackPanel>
						<TextBlock Text="Logging in store" FontWeight="Bold" />
						<TextBlock Text="{Binding ExceptionPolicy.Store.Name}" />
						<Button Content="Create error" x:Name="btnGenError" Click="btnGenError_Click" />
						<TextBlock Text="Errors currently in store" FontWeight="Bold" />
						<ListBox ItemTemplate="{StaticResource ExceptionMessageTemplate}" ItemsSource="{Binding ExceptionPolicy.Store, Mode=OneWay}" IsHitTestVisible="False" />					
					</StackPanel>
				</ScrollViewer>
			</controls:PanoramaItem>
		</controls:Panorama>

	</Grid>
</UserControl>
